package domain

import (
	"context"
	"time"
)

type Order struct {
	Id             int64
	OrderSn        string
	AppId          int32
	Status         int8
	SettleType     int8
	PriceArea      int32
	Brand          int32
	TotalPrice     int32
	OrderPrice     int32
	MerchantId     int32
	MerchantUserId int32
	PayStatus      int8
	PayMethod      int8
	PayTime        *time.Time
	RefundPrice    int32
	RefundStatus   int8
	RefundTime     *time.Time
	ReportStatus   int8
	ReportTime     *time.Time
	SalesmanId     int32
	CreatedAt      time.Time
	UpdatedAt      time.Time
	Ext            *OrderExt
	Barcodes       []*OrderBarcode
	Originals      []*OrderOriginal
	Users          []*OrderUser
}

type OrderExt struct {
	Id                int64
	Remark            string
	Department        string
	OutpatientNo      string
	BedNo             string
	ClinicalDiagnosis string
}

type OrderBarcode struct {
	Id           int64
	Barcode      string
	SamplingTime *time.Time
	Consumable   string
	Number       int8
	Status       int8
	ReportTime   *time.Time
	CreatedAt    time.Time
	UpdatedAt    time.Time
	Items        []*OrderItem
}

type OrderItem struct {
	Id           int64
	ItemCode     string
	ItemName     string
	Price        int32
	MarketPrice  int32
	ReportStatus int8
	ReportTime   *time.Time
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

type OrderUser struct {
	Id        int64
	OrderId   int64
	BarcodeId int64
	UserId    int64
	Name      string
	Age       int16
	Sex       int8
	Mobile    string
	CardType  int8
	CardId    string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type OrderOriginal struct {
	Id             int64
	ItemCode       string
	ItemName       string
	ItemCodeDetail string
	Price          int32
	MarketPrice    int32
}

type SearchOrderList struct {
	Id         int64
	OrderSn    string
	Source     int32
	Status     int8
	SettleType int8
	PriceArea  int64
	Brand      int32
	MerchantId int64
	CreatedAt  []*time.Time
	PageSize   int32
}

type OrderUsecase interface {
	ListOrders(ctx context.Context, search *SearchOrderList) ([]*Order, int, error)
	GetOrder(ctx context.Context, id int64, fields []string) (*Order, error)
	CreateOrder(ctx context.Context, do *Order) (*Order, error)
	UpdateOrder(ctx context.Context, do *Order, mask []string) (*Order, error)
	DeleteOrder(ctx context.Context, id int64) error
}

type OrderRepo interface {
	Tx(ctx context.Context) (OrderRepo, error)
	Rollback() error
	Commit() error
	ListOrders(ctx context.Context, search *SearchOrderList) ([]*Order, int, error)
	GetOrder(ctx context.Context, id int64, fields []string) (*Order, error)
	CreateOrder(ctx context.Context, do *Order) (*Order, error)
	UpdateOrder(ctx context.Context, do *Order, mask []string) (*Order, error)
	DeleteOrder(ctx context.Context, id int64) error
}
